#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   main.py
@Time    :   2021/02/05 21:18:39
@Author  :   superjin
@Version :   1.0
'''

from core import init
from fastapi import applications
from fastapi.openapi.docs import get_swagger_ui_html,get_redoc_html



def swagger_monkey_patch(*args, **kwargs):
    """
    Wrap the function which is generating the HTML for the /docs endpoint and 
    overwrite the default values for the swagger js and css.
    """
    return get_swagger_ui_html(
        *args, **kwargs,
        swagger_js_url="/npm/swagger-ui-bundle.js",
        swagger_css_url="/npm/swagger-ui.css",
        swagger_favicon_url = "/npm/favicon.png")

def swagger_monkey_patch2(*args, **kwargs):
    """
    Wrap the function which is generating the HTML for the /docs endpoint and 
    overwrite the default values for the swagger js and css.
    """
    return get_redoc_html(
        *args, **kwargs,
        redoc_js_url="/npm/redoc.standalone.js",
        redoc_favicon_url="/npm/favicon.png")
# Actual monkey patch
#applications.get_swagger_ui_html = swagger_monkey_patch
#applications.get_redoc_html = swagger_monkey_patch2
app=init.create_app()


if __name__ == "__main__":
    import uvicorn

    # 输出所有的路由
    for route in app.routes:
        if hasattr(route, "methods"):
            print({'path': route.path, 'name': route.name, 'methods': route.methods})

    uvicorn.run(app='main:app', host="0.0.0.0", port=8000, reload=True)
